package com.naiterui.ehp.bs.emr.controller.doctor;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.emr.service.IMedicalRecordTemplateService;
import com.naiterui.ehp.bs.emr.vo.MedicalRecordTemplateDetailVO;
import com.naiterui.ehp.bs.emr.vo.MedicalRecordTemplateVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * 病历模板
 * 
 * @author yangfuya
 * @since 2022/4/11
 */
@Api(tags = SwaggerTag.DOCTOR + SwaggerTag.MEDICAL_RECORD)
@RequiredArgsConstructor
@RestController
@RequestMapping("emr/template")
public class EmrMedicalRecordTemplateContoller {

    private final IMedicalRecordTemplateService medicalRecordTemplateService;

    @ApiOperation("病历模板列表")
    @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "long", paramType = "query")
    @GetMapping("list")
    public PageVO<MedicalRecordTemplateVO> list(@RequestParam Long doctorId, PageParamVO pageVO)
        throws BusinessException {
        return this.medicalRecordTemplateService.findByDoctorId(doctorId, pageVO);
    }

    @ApiOperation("病历模板保存")
    @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "long", paramType = "query")
    @PostMapping("save")
    public void save(@RequestParam Long doctorId, @RequestBody MedicalRecordTemplateDetailVO vo)
        throws BusinessException {
        this.medicalRecordTemplateService.save(doctorId, vo);
    }

    @ApiOperation("病历模板详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "病历模板ID", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "long", paramType = "query")})
    @GetMapping("detail")
    public MedicalRecordTemplateDetailVO detail(@RequestParam String id, @RequestParam Long doctorId)
        throws BusinessException {
        return this.medicalRecordTemplateService.findById(id, doctorId);
    }
}
